/**
 * Schedule defined the auto generating jobs for tasks
 * @type {[type]}
 */
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var config = require('../config');
var _ = require('lodash');
var autoIncrement = require('mongoose-auto-increment');

autoIncrement.initialize(mongoose.connection);
/* http://mongoosejs.com/docs/guide.html */
var ScheduleSchema = new Schema({
    // auto generate by autoIncrement plugin
    schedule_id: {
        type: Number,
        required: true
    },
    // daily, weekly, monthly jobs
    category: {
        type: String,
        required: true
    },
    name: {
        type: String,
        required: true
    },
    /* a child time marker of frequency,
     * eg, frequency=daily, exec_time=hour; frequency=weekly,
     * exec_time=Mon, Tue, Wen, Thu ...
     */
    time_settings: {
        type: String,
        required: true
    },
    create_date: {
        type: Date,
        default: Date.now,
        required: true
    },
    update_date: {
        type: Date,
        default: Date.now,
        required: true
    },
    author: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    assignee: {
        type: Schema.Types.ObjectId,
        ref: 'User',
        required: false
    },
    description: {
        type: String,
        required: false
    },
    visit_count: {
        type: Number,
        required: true,
        default: 0
    }
})

ScheduleSchema.plugin(autoIncrement.plugin, {
    model: 'Schedule',
    field: 'schedule_id',
    startAt: 100
});

mongoose.model('Schedule', ScheduleSchema);
module.exports = exports = ScheduleSchema;
